#!/bin/bash        
echo "Creating a Boolean flow graph, output to svg file. "
FILEENDING=".svg"
OUTFILE="$2$FILEENDING"

if [ $# -ne 2 ]
then
    echo "Usage: [inputfile] [outputfile without file ending]"
    exit
fi

if [ -f $OUTFILE ]
then
    echo "Output file [$OUTFILE] already exists"
    echo "Okay to overwrite? (y/n):"
    read answer
    if [ "$answer" = "n" ] || [ "$answer" = "N" ]
    then
      echo "Aborting"
      exit
    fi
fi

./bp2bfg/bp2bfg.byte -i $1 -format dot | ccomps -Cx | dot | gvpack -array_l1 | neato -n2 -Tsvg | sed 's/<g id=\"graph1\"/<script type=\"text\/javascript\" xlink:href=\"SVGPan.js\" \/>\n<g id=\"viewport\">\n<g id=\"graph1\"/' | sed 's/<\/svg>/<\/g>\n<\/svg>/' > $OUTFILE